import { dictAPI } from '@/api'
const state = {
    permission_routes: [
        {
            name: 'home',
            path: '/home',
            meta: {
                title: '演习与想定管理',
                icon: 'el-icon-location'
            },
            // 地图管理 地图组件库 动态地图管理 机构角色与用户 用户管理 角色
            children: [
                {
                    name: 'home-1',
                    path: '/drill-index',
                    meta: {
                        title: '演习管理'
                    },
                },
                {
                    name: 'home-2',
                    path: '/want-to-be-index',
                    meta: {
                        title: '想定管理'
                    },
                },
                {
                    name: 'home-3',
                    path: '/drill-setting-index',
                    meta: {
                        title: '开展演习设置'
                    },
                },
                {
                    name: 'home-4',
                    path: '/drill-start-index',
                    meta: {
                        title: '开展演习'
                    },
                }
            ]
        },
        {
            name: 'map',
            path: '/map',
            meta: {
                title: '地图管理',
                icon: 'el-icon-location'
            },
            children: [
                {
                    name: 'mapComponentIndex',
                    path: '/map-component-index',
                    meta: {
                        title: '地图组件库',
                    },
                },
                {
                    name: 'mapIndex',
                    path: '/map-index',
                    meta: {
                        title: '动态地图',
                    },
                }
            ]
        },
        {
            name: 'zuozhan-date',
            path: '/zuozhan-date',
            meta: {
                title: '作战时间设置',
                icon: 'el-icon-location'
            },
        }

    ],
    userList: [

    ],
    orgList: [
        {
            id: 1,
            name: '机构1'
        },
        {
            id: 2,
            name: '机构2'
        }


    ],
    userInfo: {}

}

const mutations = {
    SET_USERS(state, userList) {
        state.userList = userList
    },
    SET_ORGS(state, orgList) {
        state.orgList = orgList
    },
}

const actions = {
    getUserList({ commit }) {
        return new Promise((resolve, reject) => {
            dictAPI.getUserList().then(res => {
                commit('SET_USERS', res || [])
                resolve()
            }).catch((error) => {
                reject(error)
            })
        })
    },
    getOrgList({ commit }) {
        return new Promise((resolve, reject) => {
            dictAPI.getOrgList().then(res => {
                commit('SET_ORGS', res.rows || [])
                resolve()
            }).catch((error) => {
                reject(error)
            })
        })
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
